package cn.ven.dao;

import cn.ven.config.PassConfig;
import cn.ven.entity.MyUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public class UserDaoImpl implements UserDao {

    @Autowired
    MongoTemplate mongoTemplate;
    @Autowired
    PassConfig passConfig;

    @Override
    public void addUser(MyUser user) {
        mongoTemplate.insert(user);
    }

    @Override
    public MyUser findByUsername(String username) {
        Query query =new Query(Criteria.where("username").is(username));
        return mongoTemplate.findOne(query,MyUser.class);
    }

    @Override
    public MyUser findById(String id) {
        return mongoTemplate.findById(id,MyUser.class);
    }

    @Override
    public List<MyUser> findAll() {
        return mongoTemplate.findAll(MyUser.class);
    }



}
